Received: from svcs1.digex.net (svcs1.digex.net [204.91.197.224])
by mail1.access.digex.net (8.8.5/8.8.5) with ESMTP id SAA21802
for <mcox@access.digex.net>; Wed, 29 Jan 1997 18:57:55 -0500 (EST)
Received: (from daemon@localhost)
by svcs1.digex.net (8.8.5/8.8.5) id OAA09538
for amos-out; Wed, 29 Jan 1997 14:59:49 -0500 (EST)
Received: from mail2.access.digex.net (mail2.access.digex.net [205.197.247.3])
by svcs1.digex.net (8.8.5/8.8.5) with ESMTP id OAA09531
for <amos-list@svcs1.digex.net>; Wed, 29 Jan 1997 14:59:47 -0500 (EST)
Received: from hermes.beotel.net (ns.beotel.net [194.106.162.2])
by mail2.access.digex.net (8.8.5/8.8.5) with ESMTP id OAA17067
for <amos-list@access.digex.net>; Wed, 29 Jan 1997 14:59:44 -0500 (EST)
Received: from setnet.UUCP (Usetnet@localhost) by hermes.beotel.net (8.7.6/8.6.12) with UUCP id UAA17400 for amos-list@access.digex.net; Wed, 29 Jan 1997 20:37:22 +0100
X-Authentication-Warning: hermes.beotel.net: Usetnet set sender to setnet!smolenski using -f
Received: by setnet.co.yu (0.99.960714)
id AA02946; 28 Jan 97 14:51:31 +0100
From: smolenski@setnet.co.yu (Nikola Smolenski)
Date: 28 Jan 97 14:48:05 +0100
Subject: goto
Message-ID: <b44_9701281451@setnet.co.yu>
Organization: SETNet - Ujedinjeni BBS-ovi Balkana
To: amos-list@access.digex.net
Status: RO
X-Status:
> gs> How can I get the program to go to each label
> gs> only once? (randomly)
> I think this is the easiest:
> dim a(n)
> for i=1 to n
> a(i)=i
> next
> for i=1 to n
> r=rnd(n)+1
> goto r
> a(r)=a(n)
> dec n
> next
bu> I can't follow the logic of that program, but this program will do what
bu> was originally requested:
bu> Dim a(4)
bu> ' Store the label numbers in an array
bu> For n=0 To 4
bu> a(n)=n
bu> Next n
bu> ' Shuffle the array about, 25 times
bu> For time=1 To 25
bu> Swap a(Rnd(4)),a(Rnd(4))
bu> Next time
Yes, I like it the most:) Maybe it is a bit slower, but nothing serious.
However, here is explanation:
dim a(n)
for i=1 to n
a(i)=i
next
'all clear till now
for i=1 to n
'will do it n times
r=rnd(n)+1
goto r
'goto randomly choosen line, from n possible, n is at start size of a()
a(r)=a(n)
'last number in a() replaces used number
dec n
'n is decreased ('cause last number is moved)
next
And now I got that it could be done with rnd (0) :